<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언
    $compCd 			= $_POST['compCd'];
    $companyKR 			= $_POST['companyKR'];
    $owner 			    = $_POST['owner'];
    $phone 			    = $_POST['phone'];
    $fax 			    = $_POST['fax'];
    $addrKR 			= $_POST['addrKR'];
    $compNo 			= $_POST['compNo'];
    $compType 			= $_POST['compType'];
    $compPart 			= $_POST['compPart'];
    $email 			    = $_POST['email'];
    $flag 			    = $_POST['flag'];
    $companyEN 			= $_POST['companyEN'];
    $addrEN 			= $_POST['addrEN'];
    $major 			    = $_POST['major'];
    $majorPhone 		= $_POST['majorPhone'];
    $cellPhone 			= $_POST['cellPhone'];
    $memo 			    = $_POST['memo'];
    $oilRate 			= $_POST['oilRate'];
    $emsRate 			= $_POST['emsRate'];
    $dhlRate 		    = $_POST['dhlRate'];
    $upsRate 			= $_POST['upsRate'];
    $tntRate 			= $_POST['tntRate'];


    if($companyKR) $companyKR = iconvEncode($companyKR);
    if($owner) $owner = iconvEncode($owner);
    if($phone) $phone = iconvEncode($phone);
    if($fax) $fax = iconvEncode($fax);
    if($addrKR) $addrKR = iconvEncode($addrKR);
    if($compType) $compType = iconvEncode($compType);
    if($compPart) $compPart = iconvEncode($compPart);
    if($email) $email = iconvEncode($email);
    if($major) $major = iconvEncode($major);
    if($majorPhone) $majorPhone = iconvEncode($majorPhone);
    if($cellPhone) $cellPhone = iconvEncode($cellPhone);
    if($memo) $memo = iconvEncode($memo);

    if(!$oilRate) $oilRate = 0;
    if(!$emsRate) $emsRate = 0;
    if(!$dhlRate) $dhlRate = 0;
    if(!$upsRate) $upsRate = 0;
    if(!$tntRate) $tntRate = 0;

    if(!$issueId) $issueId = "Jade";

    $query = "EXEC spCompany ";
    $query .= "@companyKr='" .$companyKR ."' ";
    $query .= ", @companyEn='" .$companyEN ."' ";
    $query .= ", @owner='" .$owner ."' ";
    $query .= ", @phone='" .$phone ."' ";
    $query .= ", @fax='" .$fax ."' ";
    $query .= ", @major='" .$major ."' ";
    $query .= ", @majorPhone='" .$majorPhone ."' ";
    $query .= ", @cellPhone='" .$cellPhone ."' ";
    $query .= ", @compNo='" .$compNo ."' ";
    $query .= ", @compPart='" .$compPart ."' ";
    $query .= ", @compType='" .$compType ."' ";
    $query .= ", @email='" .$email ."' ";
    $query .= ", @memo='" .$memo ."' ";
    $query .= ", @flag='" .$flag ."' ";
    $query .= ", @issueId='" .$issueId ."' ";
    $query .= ", @compCd='" .$compCd ."' ";
    $query .= ", @addrKr='" .$addrKR ."' ";
    $query .= ", @addrEn='" .$addrEN ."' ";
    $query .= ", @oilRate='" .$oilRate ."' ";
    $query .= ", @emsRate='" .$emsRate ."' ";
    $query .= ", @dhlRate='" .$dhlRate ."' ";
    $query .= ", @upsRate='" .$upsRate ."' ";
    $query .= ", @tntRate='" .$tntRate ."' ";

    $logger->debug($query ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
    $rslt = mssql_query($query);

    $result = Array();
    if ($rslt == "1") {
        $result['rsStatus'] = "Success";
        $successMsg = iconvEncode("저장 되었습니다.");
    }
    else {
        $result['rsStatus'] = "Fail";
        $successMsg = iconvEncode("저장 실패");

    }
    $result['rsStr'] = urlencode($successMsg);

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($output ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>